home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Hyper / Me-Mz / MH Power Scripts v1.3.cpt / MH Power Scripts v1.3 / card_3118.txt < prev    next >
Text File  |  1988-05-06  |  13KB  |  415 lines

  1. -- card: 3118 from stack: in.3
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 2663
  5. -- name: Convert number to string
  6. ----- HyperTalk script -----
  7. Function NumToString ThisWord
  8.  
  9. -- String Convert, Copyright by Mac Help Co., January 1988
  10. -- by Chris Hostetter, Mac Help Co., 1800 East Market Street
  11. -- Long Beach, CA  90805, (213) 428-7414
  12. --      The script for this button is copyrighted and may not be
  13. --      used without the written permission of the author (above).
  14.  
  15. put ThisWord into RememberWord
  16. put empty into Millions
  17. put empty into Thousands
  18.  
  19. -- ADD THE WORD 'DOLLARS' (put false here to skip the word 'Dollars')
  20. put true into DollarPhrase
  21. -- ADD THE WORD 'CENTS' (put false here to skip the word 'Cents')
  22. put true into CentPhrase
  23.  
  24. put 0 into dollars
  25. put 0 into cents
  26. put the length of ThisWord into StringLength
  27. repeat with i = 1 to stringLength
  28.   if char i of ThisWord is "." then exit repeat
  29.   put dollars & char i of ThisWord into dollars
  30. end repeat
  31.  
  32. if i < StringLength then -- found a decimal point
  33.   -- put char i+1 to StringLength of ThisWord into cents -- All places
  34.   put char i+1 of ThisWord into cents -- Limit to 2 places
  35.   if char i+2 of ThisWord is empty then
  36.     put cents & "0" into cents
  37.   else
  38.     put cents & char i+2 of ThisWord into cents -- Limit to 2 places
  39.   end if
  40. end if
  41.  
  42. put the value of dollars into ThisWord
  43. put the length of ThisWord into stringLength
  44.  
  45. if stringLength > 6 and stringLength < 10 then
  46.   put ThisWord into RememberWord
  47.   delete char Stringlength-6+1 to StringLength of ThisWord
  48.   if the value of ThisWord is 0 then
  49.   else
  50.     put PartNumToString(ThisWord) & "Million " into Millions
  51.   end if
  52.   put char StringLength-6+1 to StringLength of RememberWord into ThisWord
  53. end if
  54.  
  55. put the length of ThisWord into StringLength
  56. if stringLength > 3 and stringLength < 7 then
  57.   put ThisWord into RememberWord
  58.   delete char Stringlength-3+1 to StringLength of ThisWord
  59.   if the value of ThisWord is 0 then
  60.   else
  61.     put PartNumToString(ThisWord) & "Thousand " into Thousands
  62.   end if
  63.   put char StringLength-3+1 to StringLength of RememberWord into ThisWord
  64. end if
  65.  
  66. put the length of ThisWord into stringLength
  67. if stringLength < 4 then
  68.   if dollarPhrase is true then
  69.     -- ***** USE THIS LINE TO INCLUDE THE WORD 'DOLLARS'
  70.     put Millions & Thousands & PartNumToString(ThisWord) & "DOLLARS" into Dollars
  71.   else
  72.     -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'DOLLARS'
  73.     put Millions & Thousands & PartNumToString(ThisWord) into Dollars
  74.   end if
  75. end if
  76.  
  77. put PartNumToString(cents) into ThisWord
  78. if ThisWord is empty then put "Zero " into ThisWord
  79.  
  80. if Dollars is "Dollars" then
  81.   if centPhrase is true then
  82.     -- ***** USE THIS LINE TO INCLUDE THE WORD 'CENTS'
  83.     put ThisWord & "CENTS" into ThisWord
  84.   else
  85.     -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'CENTS'
  86.     put ThisWord into ThisWord
  87.   end if
  88. else
  89.   if centPhrase is true then
  90.     -- ***** USE THIS LINE TO INCLUDE THE WORD 'CENTS'
  91.     put Dollars && "and" && ThisWord & "CENTS" into ThisWord
  92.   else
  93.     -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'CENTS'
  94.     put Dollars && "and" && ThisWord into ThisWord
  95.   end if
  96. end if
  97.  
  98. Return ThisWord
  99. end NumToString
  100.  
  101.  
  102. Function PartNumToString String
  103. put empty into part
  104. put String into ThisWord
  105.  
  106. if the length of thisWord is 3 then
  107.   if the value of ThisWord is 0 then
  108.     put empty into String
  109.     Return String
  110.     exit PartNumToString
  111.   end if
  112.   put first char of ThisWord into String
  113.   if the value of String is not 0 then
  114.     put GetOnes(String) & "Hundred " into part
  115.   end if
  116.   put char 2 to 3 of ThisWord into String
  117. end if
  118.  
  119. if the value of String < 20 then
  120.   put part & GetOnes(String) into String
  121. else
  122.   if string is not empty then
  123.     put the value of string into TensString
  124.     if TensString is 0 then put empty into String
  125.     if TensString > 19 then put "Twenty " into String
  126.     if TensString > 29 then put "Thirty " into String
  127.     if TensString > 39 then put "Forty " into String
  128.     if TensString > 49 then put "Fifty " into String
  129.     if TensString > 59 then put "Sixty " into String
  130.     if TensString > 69 then put "Seventy " into String
  131.     if TensString > 79 then put "Eighty " into String
  132.     if TensString > 89 then put "Ninety " into String
  133.     put part & String into Part
  134.   end if
  135.   put last char of ThisWord into String
  136.   put part & GetOnes(String) into String
  137. end if
  138.  
  139. Return String
  140. end PartNumToString
  141.  
  142.  
  143. Function GetOnes Ones
  144. if Ones is empty then exit GetOnes
  145. if the value of Ones is 0 then put empty into Ones
  146. else if Ones is 1 then put "One " into Ones
  147. else if Ones is 2 then put "Two " into Ones
  148. else if Ones is 3 then put "Three " into Ones
  149. else if Ones is 4 then put "Four " into Ones
  150. else if Ones is 5 then put "Five " into Ones
  151. else if Ones is 6 then put "Six " into Ones
  152. else if Ones is 7 then put "Seven " into Ones
  153. else if Ones is 8 then put "Eight " into Ones
  154. else if Ones is 9 then put "Nine " into Ones
  155. else if Ones is 10 then put "Ten " into Ones
  156. else if Ones is 11 then put "Eleven " into Ones
  157. else if Ones is 12 then put "Twelve " into Ones
  158. else if Ones is 13 then put "Thirteen " into Ones
  159. else if Ones is 14 then put "Fourteen " into Ones
  160. else if Ones is 15 then put "Fifteen " into Ones
  161. else if Ones is 16 then put "Sixteen " into Ones
  162. else if Ones is 17 then put "Seventeen " into Ones
  163. else if Ones is 18 then put "Eighteen " into Ones
  164. else if Ones is 19 then put "Nineteen " into Ones
  165. Return Ones
  166. end GetOnes
  167.  
  168.  
  169. -- part 1 (button)
  170. -- low flags: 00
  171. -- high flags: 8003
  172. -- rect: left=306 top=47 right=69 bottom=456
  173. -- title width / last selected line: 0
  174. -- icon id / first selected line: 0 / 0
  175. -- text alignment: 1
  176. -- font id: 0
  177. -- text size: 12
  178. -- style flags: 0
  179. -- line height: 16
  180. -- part name: Convert # to String
  181. ----- HyperTalk script -----
  182. on copyright
  183.   -- String Convert, Copyright by Mac Help Co., January 1988
  184.   -- by Chris Hostetter, Mac Help Co., 1800 East Market Street
  185.   -- Long Beach, CA  90805, (213) 428-7414
  186.   --      The script for this button is copyrighted and may not be
  187.   --      used without the written permission of the author (above).
  188. end copyright
  189.  
  190. on mouseUp
  191.   ask "Enter a number"
  192.   put it into ThisNumber
  193.   -- simply invoke the command 'NumToString(it)' and whatever is in it
  194.   -- will be changed to a string
  195.  
  196.   ask it with NumToString(ThisNumber)
  197.   put ThisNumber & ":   " & NumToString(ThisNumber) into card field ID 2
  198. end mouseUp
  199.  
  200.  
  201. Function NumToString ThisWord
  202. put ThisWord into RememberWord
  203. put empty into Millions
  204. put empty into Thousands
  205.  
  206. -- ADD THE WORD 'DOLLARS' (put false here to skip the word 'Dollars')
  207. put true into DollarPhrase
  208. -- ADD THE WORD 'CENTS' (put false here to skip the word 'Cents')
  209. put true into CentPhrase
  210.  
  211.  
  212. put 0 into dollars
  213. put 0 into cents
  214. put the length of ThisWord into StringLength
  215. repeat with i = 1 to stringLength
  216.   if char i of ThisWord is "." then exit repeat
  217.   put dollars & char i of ThisWord into dollars
  218. end repeat
  219.  
  220. if i < StringLength then -- found a decimal point
  221.   -- put char i+1 to StringLength of ThisWord into cents -- All places
  222.   put char i+1 of ThisWord into cents -- Limit to 2 places
  223.   if char i+2 of ThisWord is empty then
  224.     put cents & "0" into cents
  225.   else
  226.     put cents & char i+2 of ThisWord into cents -- Limit to 2 places
  227.   end if
  228. end if
  229.  
  230. put the value of dollars into ThisWord
  231. put the length of ThisWord into stringLength
  232.  
  233. if stringLength > 6 and stringLength < 10 then
  234.   put ThisWord into RememberWord
  235.   delete char Stringlength-6+1 to StringLength of ThisWord
  236.   if the value of ThisWord is 0 then
  237.   else
  238.     put PartNumToString(ThisWord) & "Million " into Millions
  239.   end if
  240.   put char StringLength-6+1 to StringLength of RememberWord into ThisWord
  241. end if
  242.  
  243. put the length of ThisWord into StringLength
  244. if stringLength > 3 and stringLength < 7 then
  245.   put ThisWord into RememberWord
  246.   delete char Stringlength-3+1 to StringLength of ThisWord
  247.   if the value of ThisWord is 0 then
  248.   else
  249.     put PartNumToString(ThisWord) & "Thousand " into Thousands
  250.   end if
  251.   put char StringLength-3+1 to StringLength of RememberWord into ThisWord
  252. end if
  253.  
  254. put the length of ThisWord into stringLength
  255. if stringLength < 4 then
  256.   if dollarPhrase is true then
  257.     -- ***** USE THIS LINE TO INCLUDE THE WORD 'DOLLARS'
  258.     put Millions & Thousands & PartNumToString(ThisWord) & "DOLLARS" into Dollars
  259.   else
  260.     -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'DOLLARS'
  261.     put Millions & Thousands & PartNumToString(ThisWord) into Dollars
  262.   end if
  263. end if
  264.  
  265. put PartNumToString(cents) into ThisWord
  266. if ThisWord is empty then put "Zero " into ThisWord
  267.  
  268. if Dollars is "Dollars" then
  269.   if centPhrase is true then
  270.     -- ***** USE THIS LINE TO INCLUDE THE WORD 'CENTS'
  271.     put ThisWord & "CENTS" into ThisWord
  272.   else
  273.     -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'CENTS'
  274.     put ThisWord into ThisWord
  275.   end if
  276. else
  277.   if centPhrase is true then
  278.     -- ***** USE THIS LINE TO INCLUDE THE WORD 'CENTS'
  279.     put Dollars && "and" && ThisWord & "CENTS" into ThisWord
  280.   else
  281.     -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'CENTS'
  282.     put Dollars && "and" && ThisWord into ThisWord
  283.   end if
  284. end if
  285.  
  286. Return ThisWord
  287. end NumToString
  288.  
  289.  
  290. Function PartNumToString String
  291. put empty into part
  292. put String into ThisWord
  293.  
  294. if the length of thisWord is 3 then
  295.   if the value of ThisWord is 0 then
  296.     put empty into String
  297.     Return String
  298.     exit PartNumToString
  299.   end if
  300.   put first char of ThisWord into String
  301.   if the value of String is not 0 then
  302.     put GetOnes(String) & "Hundred " into part
  303.   end if
  304.   put char 2 to 3 of ThisWord into String
  305. end if
  306.  
  307. if the value of String < 20 then
  308.   put part & GetOnes(String) into String
  309. else
  310.   if string is not empty then
  311.     put the value of string into TensString
  312.     if TensString is 0 then put empty into String
  313.     if TensString > 19 then put "Twenty " into String
  314.     if TensString > 29 then put "Thirty " into String
  315.     if TensString > 39 then put "Forty " into String
  316.     if TensString > 49 then put "Fifty " into String
  317.     if TensString > 59 then put "Sixty " into String
  318.     if TensString > 69 then put "Seventy " into String
  319.     if TensString > 79 then put "Eighty " into String
  320.     if TensString > 89 then put "Ninety " into String
  321.     put part & String into Part
  322.   end if
  323.   put last char of ThisWord into String
  324.   put part & GetOnes(String) into String
  325. end if
  326.  
  327. Return String
  328. end PartNumToString
  329.  
  330.  
  331. Function GetOnes Ones
  332. if Ones is empty then exit GetOnes
  333. if the value of Ones is 0 then put empty into Ones
  334. else if Ones is 1 then put "One " into Ones
  335. else if Ones is 2 then put "Two " into Ones
  336. else if Ones is 3 then put "Three " into Ones
  337. else if Ones is 4 then put "Four " into Ones
  338. else if Ones is 5 then put "Five " into Ones
  339. else if Ones is 6 then put "Six " into Ones
  340. else if Ones is 7 then put "Seven " into Ones
  341. else if Ones is 8 then put "Eight " into Ones
  342. else if Ones is 9 then put "Nine " into Ones
  343. else if Ones is 10 then put "Ten " into Ones
  344. else if Ones is 11 then put "Eleven " into Ones
  345. else if Ones is 12 then put "Twelve " into Ones
  346. else if Ones is 13 then put "Thirteen " into Ones
  347. else if Ones is 14 then put "Fourteen " into Ones
  348. else if Ones is 15 then put "Fifteen " into Ones
  349. else if Ones is 16 then put "Sixteen " into Ones
  350. else if Ones is 17 then put "Seventeen " into Ones
  351. else if Ones is 18 then put "Eighteen " into Ones
  352. else if Ones is 19 then put "Nineteen " into Ones
  353. Return Ones
  354. end GetOnes
  355.  
  356.  
  357. -- part 2 (field)
  358. -- low flags: 00
  359. -- high flags: 4004
  360. -- rect: left=264 top=74 right=141 bottom=509
  361. -- title width / last selected line: 0
  362. -- icon id / first selected line: 0 / 0
  363. -- text alignment: 0
  364. -- font id: 3
  365. -- text size: 9
  366. -- style flags: 0
  367. -- line height: 12
  368. -- part name: 
  369.  
  370.  
  371. -- part 3 (field)
  372. -- low flags: 01
  373. -- high flags: 0004
  374. -- rect: left=435 top=32 right=47 bottom=495
  375. -- title width / last selected line: 0
  376. -- icon id / first selected line: 0 / 0
  377. -- text alignment: 1
  378. -- font id: 3
  379. -- text size: 9
  380. -- style flags: 0
  381. -- line height: 12
  382. -- part name: See Script
  383. ----- HyperTalk script -----
  384. on mouseUp
  385.   edit script of card button "Convert # to String"
  386. end mouseUp
  387.  
  388.  
  389. -- part contents for background part 8
  390. ----- text -----
  391. Card 11 of 20
  392.  
  393. -- part contents for card part 2
  394. ----- text -----
  395. 450:   Four Hundred Fifty DOLLARS and Zero CENTS
  396.  
  397. -- part contents for background part 9
  398. ----- text -----
  399. CONVERT NUMBER TO STRING
  400.  
  401. This button can be very a very useful conversion button.  When you click on the button, you are asked to enter a number.  The number will then be converted to a string.
  402.  
  403. You can set the variables DOLLARPHRASE and CENTPHRASE to false if you don't need the words DOLLARS or CENTS added to the phrase.
  404.  
  405.  
  406.  
  407. If this script were put into the background of the card, (except for the mouseUp portion) you could convert a number to a phrase anytime simply by using  NUMTOSTRING(number).
  408.  
  409. Example:
  410. put NUMTOSTRING(450) into card field id 2
  411.  
  412.  
  413. -- part contents for card part 3
  414. ----- text -----
  415. See Script